package leetcode.sort;

import java.util.Arrays;

/**
 * @author : zx
 * @version V1.0
 */
public class BubbleSort {

    public static <V extends Comparable> void sort(V[] a){
        V tmp;
        for (int i = 0; i < a.length; i++){
            for (int j = 0; j < a.length-i-1; j++){
                if (a[j].compareTo(a[j+1]) > 0){ // 将最大的元素移动到数组尾部
                    tmp = a[j+1];
                    a[j+1] = a[j];
                    a[j] = tmp;
                }
            }
        }
    }

    public static void main(String[] args){
        Integer[] b = new Integer[]{1,4,2,2,1};
        sort(b);
        System.out.println(Arrays.toString(b));
    }
}
